/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.beaninfo.editors; import java.awt.Insets; import java.util.ResourceBundle; import org.openide.NotifyDescriptor; import org.openide.TopManager; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor; /** Custom editor for java.awt.Insets. * * @author Ian Formanek */ public class InsetsCustomEditor extends javax.swing.JPanel implements EnhancedCustomPropertyEditor { // the bundle to use static ResourceBundle bundle = NbBundle.getBundle ( InsetsCustomEditor.class); static final long serialVersionUID =-1472891501739636852L; /** Initializes the Form */ public InsetsCustomEditor(InsetsEditor editor) { initComponents (); this.editor = editor; Insets insets = (Insets)editor.getValue (); if (insets == null) insets = new Insets (0, 0, 0, 0); topField.setText (""+insets.top); // NOI18N leftField.setText (""+insets.left); // NOI18N bottomField.setText (""+insets.bottom); // NOI18N rightField.setText (""+insets.right); // NOI18N setBorder (new javax.swing.border.EmptyBorder (new java.awt.Insets(5, 5, 5, 5))); jPanel2.setBorder (new javax.swing.border.CompoundBorder ( new javax.swing.border.TitledBorder ( new javax.swing.border.EtchedBorder (), " " + bundle.getString ("CTL_Insets") + " "), new javax.swing.border.EmptyBorder (new java.awt.Insets(5, 5, 5, 5)))); HelpCtx.setHelpIDString (this, InsetsCustomEditor.class.getName ()); } public java.awt.Dimension getPreferredSize () { return new java.awt.Dimension (280, 160); } public Object getPropertyValue () throws IllegalStateException { try { int top = Integer.parseInt (topField.getText ()); int left = Integer.parseInt (leftField.getText ()); int bottom = Integer.parseInt (bottomField.getText ()); int right = Integer.parseInt (rightField.getText ()); if ((top < 0) || (left < 0) || (bottom < 0) || (right < 0)) { TopManager.getDefault().notify(new NotifyDescriptor.Message(bundle.getString("CTL_NegativeSize"), NotifyDescriptor.ERROR_MESSAGE)); Insets insets = (Insets) editor.getValue(); top = insets.top; left = insets.left; bottom = insets.bottom; right = insets.right; } return new Insets (top, left, bottom, right); } catch (NumberFormatException e) { TopManager.getDefault().notify(new NotifyDescriptor.Message(bundle.getString("CTL_InvalidValue"), NotifyDescriptor.ERROR_MESSAGE)); throw new IllegalStateException (); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents jPanel2 = new javax.swing.JPanel (); topLabel = new javax.swing.JLabel (); topField = new javax.swing.JTextField (); leftLabel = new javax.swing.JLabel (); leftField = new javax.swing.JTextField (); bottomLabel = new javax.swing.JLabel (); bottomField = new javax.swing.JTextField (); rightLabel = new javax.swing.JLabel (); rightField = new javax.swing.JTextField (); setLayout (new java.awt.BorderLayout ()); jPanel2.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; topLabel.setText (org.openide.util.NbBundle.getBundle(InsetsCustomEditor.class).getString("CTL_Top")); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; jPanel2.add (topLabel, gridBagConstraints1); topField.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { updateInsets (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 8, 4, 0); gridBagConstraints1.weightx = 1.0; jPanel2.add (topField, gridBagConstraints1); leftLabel.setText (org.openide.util.NbBundle.getBundle(InsetsCustomEditor.class).getString("CTL_Left")); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; jPanel2.add (leftLabel, gridBagConstraints1); leftField.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { updateInsets (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 8, 4, 0); gridBagConstraints1.weightx = 1.0; jPanel2.add (leftField, gridBagConstraints1); bottomLabel.setText (org.openide.util.NbBundle.getBundle(InsetsCustomEditor.class).getString("CTL_Bottom")); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; jPanel2.add (bottomLabel, gridBagConstraints1); bottomField.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { updateInsets (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 8, 4, 0); gridBagConstraints1.weightx = 1.0; jPanel2.add (bottomField, gridBagConstraints1); rightLabel.setText (org.openide.util.NbBundle.getBundle(InsetsCustomEditor.class).getString("CTL_Right")); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; jPanel2.add (rightLabel, gridBagConstraints1); rightField.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { updateInsets (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (4, 8, 4, 0); gridBagConstraints1.weightx = 1.0; jPanel2.add (rightField, gridBagConstraints1); add (jPanel2, java.awt.BorderLayout.CENTER); }//GEN-END:initComponents private void updateInsets (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateInsets try { int top = Integer.parseInt (topField.getText ()); int left = Integer.parseInt (leftField.getText ()); int bottom = Integer.parseInt (bottomField.getText ()); int right = Integer.parseInt (rightField.getText ()); editor.setValue (new Insets (top, left, bottom, right)); } catch (NumberFormatException e) { // [PENDING beep] } }//GEN-LAST:event_updateInsets // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel2; private javax.swing.JLabel topLabel; private javax.swing.JTextField topField; private javax.swing.JLabel leftLabel; private javax.swing.JTextField leftField; private javax.swing.JLabel bottomLabel; private javax.swing.JTextField bottomField; private javax.swing.JLabel rightLabel; private javax.swing.JTextField rightField; // End of variables declaration//GEN-END:variables private InsetsEditor editor; } /* * Log * 12 Gandalf 1.11 1/13/00 Petr Jiricka i18n * 11 Gandalf 1.10 1/11/00 Radko Najman fixed bug #4910 * 10 Gandalf 1.9 10/22/99 Ian Formanek NO SEMANTIC CHANGE - Sun * Microsystems Copyright in File Comment * 9 Gandalf 1.8 8/18/99 Ian Formanek Fixed bug 2322 - Some PE * couldn't be initialized - en exception is issued * 8 Gandalf 1.7 8/17/99 Ian Formanek Generated serial version * UID * 7 Gandalf 1.6 7/8/99 Jesse Glick Context help. * 6 Gandalf 1.5 6/30/99 Ian Formanek Reflecting changes in * editors packages and enhanced property editor interfaces * 5 Gandalf 1.4 6/8/99 Ian Formanek ---- Package Change To * org.openide ---- * 4 Gandalf 1.3 6/2/99 Ian Formanek Fixed event handlers * 3 Gandalf 1.2 5/31/99 Ian Formanek Updated to X2 format * 2 Gandalf 1.1 3/4/99 Jan Jancura bundle moved * 1 Gandalf 1.0 1/5/99 Ian Formanek * $ */